package top.yuechenc.manage.common.token;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import org.springframework.stereotype.Service;
import top.yuechenc.manage.entity.SpManager;

import java.util.Date;

/***
 * token 下发
 * @Title: TokenService.java
 * @version V1.0
 */
@Service("TokenService")
public class TokenService {

    public String getToken(SpManager user) {
        Date start = new Date();
        //10天有效时间
        long currentTime = System.currentTimeMillis() + 10 * 24 * 60 * 60 * 1000;
        Date end = new Date(currentTime);
        String token;

        token = JWT.create().withAudience(user.getMgName()).withIssuedAt(start).withExpiresAt(end)
                .sign(Algorithm.HMAC256(user.getMgPwd()));
        return token;
    }
}
